package com.tongtailian.www.stir.activity;

import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.tongtailian.www.stir.R;
import com.tongtailian.www.stir.adapter.ConfigAdapter;
import com.tongtailian.www.stir.adapter.SelectGroupAdapter;
import com.tongtailian.www.stir.adapter.SelectLoopNumAdapter;
import com.tongtailian.www.stir.base.BaseActivity;
import com.tongtailian.www.stir.bean.ConfigBean;
import com.tongtailian.www.stir.bean.LoopNumberBean;
import com.tongtailian.www.stir.bean.NumberBean;
import com.tongtailian.www.stir.utils.LogUtil;
import com.tongtailian.www.stir.utils.gson.GsonUtil;

import java.util.ArrayList;
import java.util.List;

import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;


public class SelectLoopNumActivity extends BaseActivity {
    private RecyclerView rvSampleNumber;


    private List<LoopNumberBean> loopNumList = new ArrayList<>();//研磨罐数量
    private SelectLoopNumAdapter selectLoopNumAdapter;
    private int loopNum;


    @Override
    public int setLayoutId() {
        return R.layout.activity_select_loop_num;
    }

    @Override
    public void initVariables() {
        setTitle("循环次数");

        loopNum = spManager.getLoopNum();

        for (int i = 1; i <= 10; i++) {
            LoopNumberBean bean = new LoopNumberBean();
            bean.setName(String.valueOf(i) + "次");
            if(i == loopNum)
                bean.setSelect(true);
            else
                bean.setSelect(false);
            loopNumList.add(bean);
        }
    }


    @Override
    protected void onResume() {
        super.onResume();
    }

    @Override
    public void initViews(Bundle savedInstanceState) {

        rvSampleNumber = findViewById(R.id.rv_sample_number);

        selectLoopNumAdapter = new SelectLoopNumAdapter(R.layout.adapter_item_loop_number, loopNumList);
        //多列创建布局管理
        GridLayoutManager gridLayoutManager = new GridLayoutManager(this, 5, GridLayoutManager.VERTICAL, false);
        gridLayoutManager.setOrientation(LinearLayoutManager.VERTICAL);
        rvSampleNumber.setLayoutManager(gridLayoutManager);
        rvSampleNumber.setAdapter(selectLoopNumAdapter);

        selectLoopNumAdapter.setOnItemClickListener(new BaseQuickAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(BaseQuickAdapter adapter, View view, int position) {
                for (LoopNumberBean loopNumberBean : loopNumList) {
                    loopNumberBean.setSelect(false);
                }
                loopNumList.get(position).setSelect(true);
                selectLoopNumAdapter.setNewData(loopNumList);
                spManager.saveLoopNum(position+1);
            }
        });


    }

    @Override
    public void doBusiness() {

    }
}